home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl150l.zip / DATA / STRTOUL.C < prev   
C/C++ Source or Header  |  1996-07-02  |  487b  |  31 lines

  1. #include <stdlib.h>
  2. #include <ctype.h>
  3. unsigned long strtoul(const char *s, char **endptr, int radix)
  4. {
  5.     int val = 0;
  6.  
  7.     while (isspace(*s)) s++;
  8.  
  9.     if (*s == '0') {
  10.         radix = 8;
  11.         s++;
  12.         if (*s == 'x' || *s == 'X') {
  13.             radix = 16;
  14.             s++;
  15.         }
  16.     }
  17.     while(isalnum(*s)) {
  18.         unsigned temp = toupper(*s++)-'0';
  19.         if (temp >= 10)
  20.             temp -= 7;
  21.         if (temp >= radix) {
  22.             s--;
  23.             break;
  24.         }
  25.         val*= radix;
  26.         val += temp;
  27.     }
  28.     if (endptr)
  29.         *endptr = s;
  30.     return val;
  31. }